package yur.wedding.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置 WebMVC 对静态资源的访问
 *
 * @Author: Yur
 * @Data:2021/11/9 20:33
 */
@Configuration
public class WebConfig   implements WebMvcConfigurer {

    /**
     * 配置对静态资源的访问
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/statics/**").addResourceLocations("classpath:/statics/");
        //
       // registry.addResourceHandler("/templates/index_admin.html").addResourceLocations("classpath:/templates/index_admin.html");
    }

    /**
     * 配置动态跨域
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .maxAge(3600);
    }

}
